<template>
<div id="login-mana">
    <div class="login-box">
      <form @submit.prevent="login">
        <h2>管理员登录</h2>
        <div class="input-group">
          <input type="text" v-model="musername" placeholder="请输入用户名" id="musername" required>
        </div>
        <div class="input-group">
          <input type="password" v-model="mpassword" placeholder="请输入用密码" id="mpassword" required>
        </div>
        <div class="input-group">
          <button type="submit" class="login-button">登录</button>
        </div>
        <br>
        <br>
        <div class="back-link">
          <router-link to="/login" class="abutton">返回用户端</router-link>
        </div>
      </form>
    </div>
</div>
</template>
  
  <script>
  import axios from 'axios';
  
  export default {
    data() {
      return {
        musername: '',
        mpassword: ''
      };
    },
    methods: {
      login() {
        let data = new FormData();
        data.append("mname", this.musername);
        data.append("mpassword", this.mpassword);
  
        axios.post("http://localhost:8080/hqdx/manager/login", data)
          .then(response => {
            if (response.data.success) {
              sessionStorage.setItem('LoginManaState', JSON.stringify(true));//登录成功，状态记录
              // 登录成功，跳转到目标页面
              this.$router.push('/manage'); // 替换为实际的管理员用户信息页面路径
            } else {
              // 登录失败，提示错误
              alert('用户名或密码错误');
            }
          })
          .catch(error => {
            console.error('请求错误:', error);
            alert('登录过程中出现问题，请重试。');
          });
      }
    }
  };
  </script>
  
  <style scoped>
  #login-mana{
    border: rgb(255, 255, 255) solid 1px;
    height: 1000px;
    background-image: url('/public/image/登录页面背景.jpg');
    background-size: 100% 100%;
  }
  
  .login-box {
    opacity: 0.75;
    width: 340px;
    padding: 20px;
    background-color: rgba(255, 255, 255, 0.8);
    border: 1px solid #ccc;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    position: relative;
    margin-top: 13%;
    margin-left: 37%;
  }
  
  .login-box h2 {
    text-align: center;
    margin-bottom: 20px;
  }
  
  .input-group {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
  }
  
  .input-group label {
    margin-bottom: 5px;
  }
  
  .input-group input[type="text"],
  .input-group input[type="password"] {
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
  }
  
  .input-group button[type="submit"] {
    padding: 10px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 10px;
  }
  
  .input-group button[type="submit"]:hover {
    background-color: #0056b3;
  }
  
  .back-link {
    position: absolute;
    bottom: 10px;
    right: 10px;
  }
  
  .abutton {
    opacity: 0.75;
    padding: 10px 20px;
    font-size: 16px;
    color: #333;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s, color 0.3s;
  }
  
  .abutton:hover {
    background-color: #e9e9e9;
    color: #000;
  }
  
  .abutton:active {
    background-color: #d4d4d4;
    color: #000;
  }
  
  .login-button {
    padding: 12px 25px;
    font-size: 16px;
    color: #ffffff;
    background: linear-gradient(145deg, #6c63ff, #9c27b0);
    border: none;
    border-radius: 24px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
  }
  
  .login-button:hover {
    background: linear-gradient(145deg, #6c63ff, #8e2de2);
    transform: translateY(-2px);
  }
  
  .login-button:active {
    background: linear-gradient(145deg, #5e50ce, #7b1fa2);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    transform: translateY(0);
  }
  
  .login-button:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(108, 99, 255, 0.5);
  }
  </style>
  